package com.itgungnir.diyshuo.activity.listview_activity;

import android.app.Activity;
import android.content.Context;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.itgungnir.diyshuo.adapter.ListViewAdapter;
import com.itgungnir.diyshuo.bean.DiyBean;
import com.itgungnir.diyshuo.bean.GoodsBean;
import com.itgungnir.diyshuo.http.diy.DiyDAO;

import java.util.List;
import java.util.Map;

import rx.Subscriber;

/**
 * ListViewActivity中相当于MVP中Model层的类
 */
public class ListViewModel implements ListViewContract.Model {
    @Override
    public void setTextToTitle(TextView tv, String text) {
        tv.setText(text);
    }

    @Override
    public void setContentToListView(final Context context, final PullToRefreshListView lv, Map<String, String> params) {
        DiyDAO.getGoodsList(params, new Subscriber<DiyBean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(DiyBean diyBean) {
                List<GoodsBean> goodsList = diyBean.getVariables().getForumThreadlist();
                lv.setAdapter(new ListViewAdapter(context, goodsList));
            }
        });
    }

    @Override
    public void onBackClickListener(Activity activity) {
        activity.finish();
    }

    @Override
    public void onListViewItemClickListener() {
    }

    @Override
    public void onListViewPullDownListener() {
    }

    @Override
    public void onListViewPullUpListener() {
    }
}